package com.chenyun.rpc.dubbo.satoken;

import cn.dev33.satoken.context.model.SaRequest;
import cn.dev33.satoken.context.model.SaResponse;
import cn.dev33.satoken.context.model.SaStorage;
import cn.dev33.satoken.context.second.SaTokenSecondContext;
import cn.dev33.satoken.exception.ApiDisabledException;
import com.chenyun.rpc.dubbo.satoken.model.SaRequestForDubbo3;
import com.chenyun.rpc.dubbo.satoken.model.SaResponseForDubbo3;
import com.chenyun.rpc.dubbo.satoken.model.SaStorageForDubbo3;
import org.apache.dubbo.rpc.RpcContext;

import java.io.Serializable;

/**
 * 移植 sa-token-dubbo3 中的代码到此处
 * @author: Lonni
 * @date: 2024/1/23 0023 15:10
 */

public class SaTokenSecondContextForDubbo3 implements SaTokenSecondContext {
    public SaRequest getRequest() {
        return (SaRequest)new SaRequestForDubbo3((RpcContext)RpcContext.getServiceContext());
    }

    public SaResponse getResponse() {
        return (SaResponse)new SaResponseForDubbo3((RpcContext)RpcContext.getServiceContext());
    }

    public SaStorage getStorage() {
        return (SaStorage)new SaStorageForDubbo3((RpcContext)RpcContext.getServiceContext());
    }

    public boolean matchPath(String pattern, String path) {
        throw new ApiDisabledException();
    }

    public boolean isValid() {
        return (RpcContext.getServiceContext() != null);
    }
}



